/**
 * Created by caozengling on 2017/10/6.
 */
var uploadfiles = new Array(); // 要上传的文件列表路径
layui.use(['jquery', 'element', 'layer', 'laydate', 'form','table','upload'], function () {
    $ = layui.jquery, element = layui.element, layer = layui.layer, laydate = layui.laydate, form = layui.form,table=layui.table;
    var billID=QueryUtils.GetQueryString("BILL_ID");
    var button=QueryUtils.GetQueryString("button");
    var type=QueryUtils.GetQueryString("type");
    var isLATE=QueryUtils.GetQueryString("isLATE");//获取是否有 滞纳金
    var hd=QueryUtils.GetQueryString("hd");//隐藏自用账单的实际收款
    var jymx=QueryUtils.GetQueryString("jymx");//显示交易明细
    var Hidden_note=QueryUtils.GetQueryString("Hidden_note");//显示交易明细
    var payment_logo=QueryUtils.GetQueryString("payment_logo");//显示交易明细
    var upload = layui.upload;
    //alert(type)
    if("edit"==button){
        $(".submits").html(" <button class=\"layui-btn layui-btn-small\" lay-submit=\"\" lay-filter=\"billedit\">确定</button>");
        //修改账单的时候 隐藏交易明细
        $(".jymx").hide();
        $(".zujin").html("<div class=\"layui-col-xs6\">\n" +
            "                                <label class=\"layui-form-label1\">房屋<span class='yingshou'>应收</span>"+type+"</label>\n" +
            "                                <div class=\"layui-inline\">\n" +
            "                                    <input type=\"text\" name=\"TOTAL_PRICE\" id=\"RENT\" lay-verify=\"title\" placeholder=\"\"\n" +
            "                                           class=\"layui-input\">\n" +
            "                                    <span class=\"label-money\">元</span>\n" +
            "                                </div>\n" +
            "                            </div>\n" +
            "                            <div class=\"layui-col-xs6\">\n" +
            "                                <label class=\"layui-form-label1\">收费类型</label>\n" +
            "                                <div class=\"layui-inline\">\n" +
            "                                    <select name=\"ALLOT_BILL\" lay-verify=\"required\" lay-search=\"\">\n" +
            "                                    <option id=\"select1\" value=\"0\">公户</option>\n" +
            "                                    <option id=\"select2\" value=\"1\">私户</option>\n" +
            "                                </select>\n" +
            "                                    <span class=\"label-money\"></span>\n" +
            "                                </div>\n" +
            "                            </div>");
        if("1"==payment_logo){
            $(".yingshou").html("应付");
        }

        $(".uploadfile").html(" <div class=\"zhangdan-jiben-info\">\n" +
            "                            <div class=\"quote-title\">\n" +
            "                                <i class=\"fa fa-circle-o\" aria-hidden=\"true\"></i>\n" +
            "                                <span>附件：</span>\n" +
            "                            </div>\n" +
            "                            <div class=\"other-info-box\">\n" +
            "                                <div class=\"attachment-info-box\">\n" +
            "                                    <!--<div class=\"attachment-administer\">\n" +
            "                                    <span>\n" +
            "                                        <i class=\"fa fa-cloud-upload\" aria-hidden=\"true\"></i>\n" +
            "                                        <span id=\"upload\">上传附件</span>\n" +
            "                                        <div class=\"layui-upload-list\" id=\"imgList\"></div>\n" +
            "                                    </span>\n" +
            "                                    </div>-->\n" +
            "                                    <div class=\"layui-upload\">\n" +
            "                                        <button type=\"button\" class=\"layui-btn layui-btn-normal\" id=\"testList\">选择多文件</button>\n" +
            "                                        <div class=\"layui-upload-list\">\n" +
            "                                            <table class=\"layui-table\">\n" +
            "                                                <thead>\n" +
            "                                                <tr>\n" +
            "                                                    <th>缩略图</th>\n" +
            "                                                    <th>文件名</th>\n" +
            "                                                    <th>大小</th>\n" +
            "                                                    <th>状态</th>\n" +
            "                                                    <th>操作</th>\n" +
            "                                                </tr></thead>\n" +
            "                                                <tbody id=\"demoList\"></tbody>\n" +
            "                                            </table>\n" +
            "                                        </div>\n" +
            "                                        <button type=\"button\" class=\"layui-btn\" id=\"testListAction\">开始上传</button>\n" +
            "                                    </div>\n" +
            "                                </div>\n" +
            "                            </div>\n" +
            "                        </div>");

    }else {
        //自用账单的查看
        if("1"==hd){
            $(".zujin").html("<div class=\"layui-col-xs6\">\n" +
                "                                <label class=\"layui-form-label1\">房屋<span class='yingshou'>应收</span>"+type+"</label>\n" +
                "                                <div class=\"layui-inline\">\n" +
                "                                    <input type=\"text\" name=\"TOTAL_PRICE\" id=\"RENT\" lay-verify=\"title\" placeholder=\"\"\n" +
                "                                           class=\"layui-input\" readonly>\n" +
                "                                    <span class=\"label-money\">元</span>\n" +
                "                                </div>\n" +
                "                            </div>\n" +
                "                            " +
                "                                    <div class=\"layui-col-xs6\">\n" +
                "                                        <label class=\"layui-form-label1\">收费类型</label>\n" +
                "                                        <div class=\"layui-inline\">\n" +
                "                                            <input type=\"text\" name=\"ALLOT_BILL\" id=\"ALLOT_BILL\" lay-verify=\"title\"\n" +
                "                                                   placeholder=\"\"\n" +
                "                                                   class=\"layui-input\" readonly>\n" +
                "                                            <span class=\"label-money\"></span>\n" +
                "                                        </div>\n" +
                "                                    </div>\n");
            if("1"==payment_logo){
                $(".yingshou").html("应付");
            }
        }else if(hd=="0"){
            $(".zujin").html("<div class=\"layui-col-xs6\">\n" +
                "                                <label class=\"layui-form-label1\">房屋<span class='yingshou'>应收</span>"+type+"</label>\n" +
                "                                <div class=\"layui-inline\">\n" +
                "                                    <input type=\"text\" name=\"TOTAL_PRICE\" id=\"RENT\" lay-verify=\"title\" placeholder=\"\"\n" +
                "                                           class=\"layui-input\" readonly>\n" +
                "                                    <span class=\"label-money\">元</span>\n" +
                "                                </div>\n" +
                "                            </div>\n" +
                "                            " +
                "                                    <div class=\"layui-col-xs6\">\n" +
                "                                        <label class=\"layui-form-label1\">收费类型</label>\n" +
                "                                        <div class=\"layui-inline\">\n" +
                "                                            <input type=\"text\" name=\"ALLOT_BILL\" id=\"ALLOT_BILL\" lay-verify=\"title\"\n" +
                "                                                   placeholder=\"\"\n" +
                "                                                   class=\"layui-input\" readonly>\n" +
                "                                            <span class=\"label-money\"></span>\n" +
                "                                        </div>\n" +
                "                                    </div>\n");
            if("1"==payment_logo){
                $(".yingshou").html("应付");
            }

        }else if(hd=="2"){
            $(".zujin").html("<div class=\"layui-col-xs6\">\n" +
                "                                <label class=\"layui-form-label1\">房屋<span class='yingshou'>应收</span>"+type+"</label>\n" +
                "                                <div class=\"layui-inline\">\n" +
                "                                    <input type=\"text\" name=\"TOTAL_PRICE\" id=\"RENT\" lay-verify=\"title\" placeholder=\"\"\n" +
                "                                           class=\"layui-input\" readonly>\n" +
                "                                    <span class=\"label-money\">元</span>\n" +
                "                                </div>\n" +
                "                            </div>\n" +
                "                            " +
                "                                    <div class=\"layui-col-xs6\">\n" +
                "                                        <label class=\"layui-form-label1\">收费类型</label>\n" +
                "                                        <div class=\"layui-inline\">\n" +
                "                                            <input type=\"text\" name=\"TYPE_SHOU\" id=\"TYPE_SHOU\" lay-verify=\"title\"\n" +
                "                                                   placeholder=\"\"\n" +
                "                                                   class=\"layui-input\" readonly>\n" +
                "                                            <span class=\"label-money\"></span>\n" +
                "                                        </div>\n" +
                "                                    </div>\n");
            if("1"==payment_logo){
                $(".yingshou").html("应付");
            }
        }else {
            $(".zujin").html("<div class=\"layui-col-xs6\">\n" +
                "                                <label class=\"layui-form-label1\">房屋<span class='yingshou'>应收</span>"+type+"</label>\n" +
                "                                <div class=\"layui-inline\">\n" +
                "                                    <input type=\"text\" name=\"TOTAL_PRICE\" id=\"RENT\" lay-verify=\"title\" placeholder=\"\"\n" +
                "                                           class=\"layui-input\" readonly>\n" +
                "                                    <span class=\"label-money\">元</span>\n" +
                "                                </div>\n" +
                "                            </div>\n" +
                "                            " +
                "                                    <div class=\"layui-col-xs6\">\n" +
                "                                        <label class=\"layui-form-label1\">收费类型</label>\n" +
                "                                        <div class=\"layui-inline\">\n" +
                "                                            <input type=\"text\" name=\"ALLOT_BILL\" id=\"ALLOT_BILL\" lay-verify=\"title\"\n" +
                "                                                   placeholder=\"\"\n" +
                "                                                   class=\"layui-input\" readonly>\n" +
                "                                            <span class=\"label-money\"></span>\n" +
                "                                        </div>\n" +
                "                                    </div>\n");
        }
        $(".uploadfile").html('<div class="zhangdan-jiben-info">\n' +
            '                            <div class="quote-title">\n' +
            '                                <i class="fa fa-circle-o" aria-hidden="true"></i>\n' +
            '                                <span>附件</span>\n' +
            '                            </div>\n' +
            '                            <div>\n' +
            '                                <div class="layui-form-item">\n' +
            '                                    <div class="layui-inline layui-inline-normal attachments">\n' +
            '                                        <!--<div class="layui-input-inline">\n' +
            '                                            <span>1</span>\n' +
            '                                            <span>附件1</span>\n' +
            '                                            <span>下载</span>\n' +
            '                                        </div>-->\n' +
            '                                    </div>\n' +
            '                                </div>\n' +
            '                            </div>\n' +
            '                        </div>');
        $("input").attr("readOnly", "readOnly");
    }
    //已收账单的查看 和 流水明细的查看 显示交易明细
    if("1"==jymx){
        $(".Hidden_note").hide();
        $(".hide_jymx").html("<div class=\"zhangdan-jiben-info\">\n" +
            "                                <div class=\"jymx\">\n" +
            "                                    <div class=\"layui-row\">\n" +
            "                                        <div class=\"layui-col-xs2\">\n" +
            "                                            交易明细\n" +
            "                                        </div>\n" +
            "                                    </div>\n" +
            "                                    <hr>\n" +
            "                                    <table id=\"jymx\"></table>\n" +
            "                                    <hr>\n" +
            "                                </div>\n" +
            "                            </div>");

    }

    //加载 租金 电费 押金 等 的明细
    //租金
    if("0"==type){
        $(".zujin").html("<div class=\"layui-col-xs6\">\n" +
            "                                <label class=\"layui-form-label1\">房屋应收租金</label>\n" +
            "                                <div class=\"layui-inline\">\n" +
            "                                    <input type=\"text\" name=\"TOTAL_PRICE\" id=\"RENT\" lay-verify=\"title\" placeholder=\"\"\n" +
            "                                           class=\"layui-input\">\n" +
            "                                    <span class=\"label-money\">元</span>\n" +
            "                                </div>\n" +
            "                            </div>\n" +
            "                            <div class=\"layui-col-xs6\">\n" +
            "                                <label class=\"layui-form-label1\">收费类型</label>\n" +
            "                                <div class=\"layui-inline\">\n" +
            "                                    <select name=\"ALLOT_BILL\" lay-verify=\"required\" lay-search=\"\">\n" +
            "                                    <option id=\"select1\" value=\"0\">公户</option>\n" +
            "                                    <option id=\"select2\" value=\"1\">私户</option>\n" +
            "                                </select>\n" +
            "                                    <span class=\"label-money\"></span>\n" +
            "                                </div>\n" +
            "                            </div>");
    }
    //押金
    if("1"==type){
        $(".yajin").html("<div class=\"layui-col-xs6\">\n" +
            "                                <label class=\"layui-form-label1\">房屋应收押金</label>\n" +
            "                                <div class=\"layui-inline\">\n" +
            "                                    <input type=\"text\" name=\"TOTAL_PRICE\" id=\"BOND\" lay-verify=\"title\" placeholder=\"\"\n" +
            "                                           class=\"layui-input\">\n" +
            "                                    <span class=\"label-money\">元</span>\n" +
            "                                </div>\n" +
            "                            </div>\n" +
            "                            <div class=\"layui-col-xs6\">\n" +
            "                                <label class=\"layui-form-label1\">收费类型</label>\n" +
            "                                <div class=\"layui-inline\">\n" +
            "                                    <input type=\"text\" name=\"\" id=\"ALLOT_BILL\" lay-verify=\"title\" placeholder=\"\" class=\"layui-input\">\n" +
            "                                    <span class=\"label-money\"></span>\n" +
            "                                </div>\n" +
            "                            </div>");
    }
    //水费
    if("2"==type){
        $(".shuifei").html("<div class=\"layui-col-xs6\">\n" +
            "                                <label class=\"layui-form-label1\">应收水费</label>\n" +
            "                                <div class=\"layui-inline\">\n" +
            "                                    <input type=\"text\" name=\"TOTAL_PRICE\"  id=\"yssf\" lay-verify=\"title\" placeholder=\"\" class=\"layui-input\">\n" +
            "                                    <span class=\"label-money\">元</span>\n" +
            "                                </div>\n" +
            "                            </div>\n" +
            "                            <div class=\"layui-col-xs6\">\n" +
            "                                <label class=\"layui-form-label1\">收费类型</label>\n" +
            "                                <div class=\"layui-inline\">\n" +
            "                                    <input type=\"text\" name=\"\" id=\"ALLOT_BILL\" lay-verify=\"title\" placeholder=\"\" class=\"layui-input\">\n" +
            "                                    <span class=\"label-money\"></span>\n" +
            "                                </div>\n" +
            "                            </div>");
        $(".sfcbsj").html("<div class=\"layui-col-xs6\">\n" +
            "                                <label class=\"layui-form-label1\">抄表时间</label>\n" +
            "                                <div class=\"layui-inline\">\n" +
            "                                    <input type=\"text\" name=\"\" lay-verify=\"title\" id=\"cbsj\" autocomplete=\"off\"\n" +
            "                                           placeholder=\"抄表时间\" class=\"layui-input\">\n" +
            "                                </div>\n" +
            "                            </div>");
    }


    //渲染下拉框
    form.render("select");
    //加载交易明细
    var data={};
    data.ID=billID;
    //alert(billID);
    table.render({
        elem: '#jymx'
        , url: '/billController/listjymx'
        ,where:data
        ,cols: [[ //标题栏
            {checkbox: true, LAY_CHECKED: true} //默认全选
            ,{field: 'CREATE_DATE', title: '交易时间', width: 180}
            ,{field: 'NAME', title: '操作人', width: 120}
            ,{field: 'PAY_METHOD', title: '交易方式', width: 130}
            ,{field: 'PAY_PRICE', title: '交易金额', width: 120}
            ,{field: 'PAY_TRANSACTION', title: '交易流水号', width: 160}
            ,{field: 'COLLECTION_TYPE', title: '收费类型', width: 120}
            ,{field: 'INFO', title: '备注', width: 180}
        ]]
        , id: ''
        , page: true
        , height: 'auto'
        , limit: '10'
    });
    //开始日期
    laydate.render({
        elem: '#start'
        ,format: 'yyyy-MM-dd'
    });
    //结束日期
    laydate.render({
        elem: '#end'
        ,format: 'yyyy-MM-dd'
    });
    //应付款时间
    laydate.render({
        elem: '#pay_date'
        ,format: 'yyyy-MM-dd'
    });
    //实际收租时间
    laydate.render({
        elem: '#ACT_PAY_DATE'
        ,format: 'yyyy-MM-dd'
    });
    //抄表时间
    laydate.render({
        elem: '#cbsj'
        ,format: 'yyyy-MM-dd'
    });
    $(".cancel").click(function () {
        var index = parent.layer.getFrameIndex(window.name); // 先得到当前iframe层的索引
        parent.layer.close(index); // 再执行关闭
    });
    //加载查看账单数据
    var billID=QueryUtils.GetQueryString("BILL_ID");//账单ID
    //获取 账单基本信息 查看
    $.ajax({
        url: "/billController/listBill/",
        data: {ID:billID},
        dataType: "json",
        type: "post",
        async: false,
        success: function (res) {
            if (res.errcode === "0") {
                //加载 账单基本信息
                $("#ID").val(res.data.ID);
                $("#ROOM_NUM").val(res.data.ROOM_NUM);
                $("#COMPANY_NAME").val(res.data.COMPANY_NAME);
                $("#START_DATE").val(res.data.START_DATE);
                $("#END_DATE").val(res.data.END_DATE);
                $("#PAY_DATE").val(res.data.PAY_DATE);
                if(!!res.data.ACT_PAY_DATE){
                    $("#ACT_PAY_DATE").val(res.data.ACT_PAY_DATE);//实际收租时间
                }
                $("#SIGNER").val(res.data.SIGNER);
                $("#RENT").val(res.data.TOTAL_PRICE);
                $("#PARK_CARD").val(res.data.PARK_CARD);//张数
                $("#PAY_PRICE").val(res.data.PAY_PRICE);//实际收的金额
                if(res.data.PARK_CARD==""){
                    $("#TYPE_SHOU").val("收入");//张数 /实际收的金额
                    $("#PARK_CARD").val("0");//张数
                }else{
                    $("#TYPE_SHOU").val("卡");//张数 /实际收的金额
                    $("#RENT").val("0");//实际收的金额
                }
                if(res.data.TOTAL_PRICE!=null  && res.data.TOTAL_PRICE!=""){
                    $("#RENT").val(res.data.TOTAL_PRICE);
                }


                $("#BOND").val(res.data.BOND);
                $("#COMPANY_NAME").val(res.data.COMPANY_NAME);//承租方
                $("#yssf").val(res.data.TOTAL_PRICE);
                $("#ysdf").val(res.data.TOTAL_PRICE);
                $("#BOND").val(res.data.TOTAL_PRICE);

                $("#rqf").val(res.data.TOTAL_PRICE);
                $("#INFO").val(res.data.INFO);
                $("#ALLOT_BILL").val(res.data.ALLOT_BILL);
                if("公户"===res.data.ALLOT_BILL){
                    $("#select1").attr("selected","selected");
                }
                if("私户"===res.data.ALLOT_BILL){
                    $("#select2").attr("selected","selected");
                }
                form.render("select");
                //收费信息
                var zujin=res.data.TOTAL_PRICE;
                var yajin=res.data.BOND;
                var zafei=res.data.TOTAL_PRICE;
                $("#zujin").html(zujin);
                $("#yajin").html(yajin);
                if(typeof(zujin)=="undefined"||yajin=="undefined"){
                    zujin=0;
                    yajin=0;
                }
                $("#zafei").html(res.data.TOTAL_PRICE);
                $("#xiaoji").html((parseFloat(zujin)+parseFloat(yajin)));
               /* //加载附件
                var attachment = res.attachment;
                    //$(".attachments").empty();
                    if (!!attachment) {
                        for (var i = 0; i < attachment.length; i++) {
                            var str = '<div class="layui-input-block">\n' +
                                '          <span>' + (i + 1) + '</span>\n' +
                                '          <span>' + attachment[i].NAME + '</span>\n' +
                                '          <span><a href="http://' + window.location.host + '/' + attachment[i].PATH + '" target="_blank" class=\"layui-btn layui-btn-mini layui-btn-normal\">下载</a></span>\n' +
                                '      </div>';
                            $(".attachments").append(str);
                        }
                    }*/
                // 初始化附件
                if("edit"==button){
                    var attachments = res.attachmentData;
                    if (!!attachments) {
                        var host = location.host;
                        for (var i = 0; i < attachments.length; i++) {
                            var attachment = attachments[i];
                            var demoListView = $('#demoList');
                            var tr = $(['<tr id="upload-' + (i + 1) + '">'
                                , '<td><img src="http://' + host + '/' + attachment.PATH + '" alt="' + attachment.NAME + '" class="layui-upload-img"></td>'
                                , '<td>' + attachment.NAME + '</td>'
                                , '<td>' + (attachment.SIZE / 1014).toFixed(1) + 'kb</td>'
                                , '<td><span style="color: #5FB878;">上传成功</span></td>'
                                , '<td>'
                                , '<a onclick=\'operate.deleteImg(this, "' + attachment.ID + '");\' class="layui-btn layui-btn-mini layui-btn-danger demo-delete">删除</a>'
                                , '</td>'
                                , '</tr>'].join(''));
                            demoListView.append(tr);

                            var obj = {};
                            obj.id = attachment.ID;
                            obj.name = attachment.NAME;
                            obj.size = attachment.SIZE;
                            obj.ext = attachment.EXT;
                            obj.url = attachment.PATH;
                            uploadfiles.push(obj);
                        }
                    }
                }else {
                    var attachments = res.attachmentData;
                    if (!!attachments) {
                        var host = location.host;
                        for (var i = 0; i < attachments.length; i++) {
                            var str = '<div class="layui-input-block">\n' +
                                '          <span>' + (i + 1) + '</span>\n' +
                                '          <span>' + attachments[i].NAME + '</span>\n' +
                                '          <span><a href="http://' + window.location.host + '/' + attachments[i].PATH + '" target="_blank" class=\"layui-btn layui-btn-mini layui-btn-normal\">下载</a></span>\n' +
                                '      </div>';
                            $(".attachments").append(str);
                        }
                    }
                }

            } else if (res.errcode === "1") {
                layer.msg(res.errmsg, function () {
                });
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.error(XMLHttpRequest.status);
            console.error(XMLHttpRequest.readyState);
            console.error(textStatus);
        }
    });
    if("1"==button){
        //获取 实际 支付信息
        $.ajax({
            url: "/billController/listbilljson/",
            data: {ID:billID},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    //加载 账单实际基本信息
                    //alert(res.data.ID);
                    $(".sjszTIME").html("<div class=\"layui-col-xs6\">\n" +
                        "                                    <label class=\"layui-form-label1\">实际收租时间</label>\n" +
                        "                                    <div class=\"layui-inline\">\n" +
                        "                                        <input type=\"text\" name=\"\" id=\"ACT_PAY_DATE\" lay-verify=\"title\"\n" +
                        "                                               autocomplete=\"off\"\n" +
                        "                                               placeholder=\"\" class=\"layui-input\">\n" +
                        "                                    </div>\n" +
                        "                                </div>");
                    if(!!res.data.ACT_PAY_DATE){
                        $("#ACT_PAY_DATE").val(res.data.ACT_PAY_DATE);
                    }
                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });
    }
    //监听 修改账单
    //监听提交
    form.on('submit(billedit)', function(data){
        data=data.field;
        //console.log(data);
        data.ID=billID;
        data.ATTACHMENT = uploadfiles;
        console.log(uploadfiles)
        data.CHECK_STATE='0';
        layer.msg('确认修改吗', {
            time: 0
            , btn: ['确定', '取消']
            , shade: 0.3
            , yes: function (index) {
                $.ajax({
                    url: "/billController/billedit",
                    data: data,
                    dataType: "json",
                    type: "post",
                    async: false,
                    success: function (res) {
                        if (res.errcode === "0") {
                            var i = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(i);  // 关闭修改房间页面
                            // window.parent.frames[0].reload(); // 调用父页面中的iframe中的重新加载方法
                            parent.layer.msg("修改成功,待审核", {offset: '150px'});   // 父页面弹出修改成功
                            window.parent.frames[0].reloadszTbale();//刷新 未收账单
                            window.parent.frames[0].reloadspTbale();//刷新 审批账单
                            window.parent.frames[0].reloadtzTbale();//刷新
                            window.parent.frames[0].reloadyfTbale();//刷新 应付
                            window.parent.frames[0].reloadyclTbale();//刷新 已收列表
                            window.parent.frames[0].reloadyqlbTbale();//刷新 逾期列表
                        } else if (res.errcode === "1") {
                            layer.msg(res.errmsg, function () {
                            });
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.error(XMLHttpRequest.status);
                        console.error(XMLHttpRequest.readyState);
                        console.error(textStatus);
                    }

                });


            }
        });
        return false;
    });

    //监听审核 通过
    form.on('submit(billpass)', function(data){
        data=data.field;
        data.ID=billID;
        layer.msg('确认通过吗', {
            time: 0
            , btn: ['确定', '取消']
            , shade: 0.3
            , yes: function (index) {
                $.ajax({
                    url: "/billController/billedit",
                    data: data,
                    dataType: "json",
                    type: "post",
                    async: false,
                    success: function (res) {
                        if (res.errcode === "0") {
                            var i = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(i);  // 关闭修改房间页面
                            parent.layer.msg("收款成功", {offset: '150px'});   // 父页面弹出修改成功
                        } else if (res.errcode === "1") {
                            layer.msg(res.errmsg, function () {
                            });
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.error(XMLHttpRequest.status);
                        console.error(XMLHttpRequest.readyState);
                        console.error(textStatus);
                    }
                });
            }
        });
        return false;
    });

    //操作详情
    var data={};
    data.BILL_ID=billID;
    //alert(billID);
    //alert(data.CONTRACT_ID);
    table.render({
        elem: '#historySH'
        , url: '/recordController/list'
        , where:data
        , cols: [[
            {field: 'DETAILS', event: 'setSign', title: '操作详情', width: 700}
            , {field: 'OPERATOR', event: 'setSign', title: '操作人', width: 150}
            , {field: 'OPERA_TIME', event: 'setSign', title: '操作时间', width: 150}

        ]]
        , id: ''
        , page: true
        , height: 'auto'
        , limit: '10'
        ,size: 'sm' //小尺寸的表格
    });

    //多文件列表示例
    debugger
    var files;
    var demoListView = $('#demoList')
        , uploadListIns = upload.render({
        elem: '#testList'
        , url: '/servlet/UploadHandleServlet'
        // ,accept: 'file'
        , multiple: true
        , auto: false
        , bindAction: '#testListAction'
        , choose: function (obj) {
            files = obj.pushFile(); //将每次选择的文件追加到文件队列
            //读取本地文件
            obj.preview(function (index, file, result) {
                var tr = $(['<tr id="upload-' + index + '">'
                    , '<td><img src="' + result + '" alt="' + file.name + '" class="layui-upload-img"></td>'
                    , '<td>' + file.name + '</td>'
                    , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                    , '<td>等待上传</td>'
                    , '<td>'
                    , '<button class="layui-btn layui-btn-mini demo-reload layui-hide">重传</button>'
                    , '<button class="layui-btn layui-btn-mini layui-btn-danger demo-delete">删除</button>'
                    , '</td>'
                    , '</tr>'].join(''));

                //单个重传
                tr.find('.demo-reload').on('click', function () {
                    obj.upload(index, file);
                    return false;
                });

                //删除
                tr.find('.demo-delete').on('click', function () {
                    delete files[index]; //删除对应的文件
                    tr.remove();
                });

                demoListView.append(tr);
            });
        }
        , done: function (res, index, upload) {
            if (res.errcode == 0) { //上传成功
                var obj = {};
                obj.name = res.data.fileName;
                obj.ext = res.data.extName;
                obj.url = res.data.fileUrl;
                obj.size = res.data.fileSize;
                uploadfiles.push(obj);
                var tr = demoListView.find('tr#upload-' + index)
                    , tds = tr.children();
                tds.eq(3).html('<span style="color: #5FB878;">上传成功</span>');
                tds.eq(4).html(''); //清空操作
                delete files[index]; //删除文件队列已经上传成功的文件
                return;
            }
            this.error(index, upload);
        }
        , error: function (index, upload) {
            var tr = demoListView.find('tr#upload-' + index)
                , tds = tr.children();
            tds.eq(3).html('<span style="color: #FF5722;">上传失败</span>');
            tds.eq(4).find('.demo-reload').removeClass('layui-hide'); //显示重传
        }
    });
});
var operate = {
    deleteImg: function (obj, id) {
        $(obj).parent().parent().remove();
        for (var i = 0; i < uploadfiles.length; i++) {
            if (uploadfiles[i].id == id) {
                uploadfiles.splice(i, 1);
            }
        }
    }
}